package org.jeecg.modules.wmhb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.constant.UserConstant;
import org.jeecg.modules.wmhb.entity.WmContract;
import org.jeecg.modules.wmhb.entity.WmProject;
import org.jeecg.modules.wmhb.mapper.WmProjectMapper;
import org.jeecg.modules.wmhb.service.IWmProjectService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 项目表
 * @Author: jeecg-boot
 * @Date:   2024-09-02
 * @Version: V1.0
 */
@Service
public class WmProjectServiceImpl extends ServiceImpl<WmProjectMapper, WmProject> implements IWmProjectService {
    @Override
    public String checkCodeUnique(WmProject wmProject){
        WmProject item = baseMapper.checkCodeUnique(wmProject);
        String itemId = wmProject.getId() == null ? "" : wmProject.getId();
        if(item != null && !itemId.equals(item.getId())){
            return UserConstant.NOT_UNIQUE;
        }else{
            return UserConstant.UNIQUE;
        }
    };

    @Override
    public String checkNameUnique(WmProject wmProject){
        WmProject item = baseMapper.checkNameUnique(wmProject);
        String itemId = wmProject.getId() == null ? "" : wmProject.getId();
        if(item != null && !itemId.equals(item.getId())){
            return UserConstant.NOT_UNIQUE;
        }else{
            return UserConstant.UNIQUE;
        }
    };

    @Override
    public boolean checkHasItem(String id) {
        int num = baseMapper.hasItemById(id);
        return num >0 ? true:false;
    };

    @Override
    public List<WmProject> confirmedProjectList(){
        LambdaQueryWrapper<WmProject> queryWrapper = new LambdaQueryWrapper<>();
        List<String> statusList = new ArrayList<>();
        statusList.add(UserConstant.PROJECT_STATUS_PREPARE);
        queryWrapper.notIn(WmProject::getStatus, statusList);
        return list(queryWrapper);
    };

    @Override
    public List<WmProject> searchByName(String searchKey){
        LambdaQueryWrapper<WmProject> queryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(searchKey)) {
            queryWrapper.like(WmProject::getName, searchKey);
        }
        return list(queryWrapper);
    };
}
